<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #operationBeforeExtend="{ record }">
        <a-link @click="openList(record)"><icon-list />明细</a-link>
      </template>
    </ma-crud>
    <execl-template ref="execlTemplate" />
    <data-list ref="datalist" />
  </div>
</template>
<script setup>
import {ref, reactive,provide} from 'vue'
import templateExcelExport from '@/api/template/templateExcelExport'
import DataList from "./dataList.vue";
import dictHelp from "@/utils/dicthelp.js";
import ExeclTemplate from "@/views/template/excelExport/execlTemplate.vue";

const crudRef = ref()

const datalist = ref()
const execlTemplate = ref();
const options = reactive({
  id: 'template_excel_export',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: templateExcelExport.getList,
  recycleApi: templateExcelExport.getRecycleList,
  add: {
    show: true,
    api: templateExcelExport.save,
    auth: ['template:excelExport:save'],
    action:()=>{
      execlTemplate.value.open()
    }
  },
  edit: {
    show: true,
    api: templateExcelExport.update,
    auth: ['template:excelExport:update'],
    action:(record)=>{
      execlTemplate.value.open(record)
    }
  },
  delete: {
    show: true,
    api: templateExcelExport.deletes,
    auth: ['template:excelExport:delete'],
    realApi: templateExcelExport.realDeletes,
    realAuth: ['template:excelExport:realDeletes']
  },
  recovery: {
    show: true,
    api: templateExcelExport.recoverys,
    auth: ['template:excelExport:recovery']
  }
})

const columns = reactive([
  {
    title: "主键",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
  },
  {
    title: "模板名称",
    dataIndex: "name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入模板名称"
    }
  },
  {
    title: "类型",
    dataIndex: "type",
    formType: "radio",
    type:'button',
    addDefaultValue: 2,
    search: true,
    commonRules: {
      required: true,
      message: "请输入类型"
    },
    dict: {
      data:[
        {label:'客户',value:1},
        {label:'员工',value:2},
      ],
      translation: true
    }
  },
  // {
  //   title: "顶部预留行数",
  //   dataIndex: "start_line",
  //   formType: "input-number",
  //   commonRules: {
  //     required: true,
  //     message: "请输入顶部预留行数"
  //   },
  //   max: 255,
  //   min: 1,
  //   step: 1
  // },
  {
    title: "系统模板",
    dataIndex: "system_template",
    formType: "switch",
    commonRules: {
      required: true,
      message: "请输入系统模板"
    },
    checkedValue: 1,
    uncheckedValue: 0,
    customRender: ({record}) => {
      return record.system_template == 1 ? '是' : '否'
    }
  },
  {
    title: "导出类型",
    dataIndex: "export_main_object_name",
    formType: "cascader",
    search: true,
    commonRules: {
      required: true,
      message: "请输入导出类型"
    },
    multiple: false,
    dict: {
      url:'template/excelObject/index',
      props: {
        label: 'name',
        value: 'id',
        parentId:'parent_id'
      },
      translation: true
    }
  },
  {
    title: "创建人",
    dataIndex: "created_by",
    formType: "select",
    dict:dictHelp.user,
    addDisplay:false,
    editDisplay:false,
  },
  // {
  //   title: "明细单行显示",
  //   dataIndex: "detail_one_line",
  //   formType: "input",
  //   commonRules: {
  //     required: true,
  //     message: "请输入明细单行显示"
  //   }
  // },
  // {
  //   title: "客户ID,为系统模板时，客户ID为0",
  //   dataIndex: "object_id",
  //   formType: "input",
  //   addDisplay: false,
  //   editDisplay: false,
  //   hide: true
  // },
  // {
  //   title: "状态",
  //   dataIndex: "status",
  //   formType: "switch",
  //   addDefaultValue: true,
  //   checkedValue: true,
  //   uncheckedValue: false,
  //   commonRules: {
  //     required: true,
  //     message: "请输入状态"
  //   }
  // },
])

const openList = async (row) => {
  datalist.value.open(row)
}
provide('crudRef',crudRef)
</script>
<script> export default {name: 'template:excelExport'} </script>